﻿using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Net;
using System.Windows.Forms;
using Commands.Settings;
using Commands.TorrentDownloaders;
using System.Collections.Generic;
using Commands;
using Commands.Commands;

namespace CommonCommandsPlugin
{
    /// <summary>
    /// Class with commands which can be executed.
    /// </summary>
    internal class CommandsList : CommandListBase   
    {
        #region Commands

        /// <summary>
        /// Send folder structure.
        /// </summary>
        /// <param name="depth">Depth of the scan, 5 for default.</param>
        /// <param name="path">Path to root folder.</param>
        [RemoteCommand("Send folder structure.", "stucture", "struct")]
        public bool GetFolderStructure(
            [Parameter("Path to root folder.", typeof(string), true, "p", "path", "root")] string path,
            [Parameter("Depth of the scan, 5 for default.", typeof(int?), false, "d", "depth")] int? depth,
            [MailAddressParameter()] string mail)
        {
            var structure = FolderStructure.Get(path, false, depth);

            Mailer.SendMail(mail, "Folders", structure);

            return true;
        }

        /// <summary>
        /// Send printscreen.
        /// </summary>
        [RemoteCommand("Send printscreen.", "ps", "screen", "printscreen")]
        public bool PrintScreen([MailAddressParameter()] string mailAddress)
        {
            // Get screen image.
            Bitmap printscreen = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                Screen.PrimaryScreen.Bounds.Height);
            using (Graphics graphics = Graphics.FromImage(printscreen as Image))
            {
                graphics.CopyFromScreen(0, 0, 0, 0, printscreen.Size, CopyPixelOperation.SourceCopy);
            }

            // Save it to a file.
            string fileName = FilesHelper.GetTempFilePath(DateTime.Now.ToString() + ".jpeg");
            fileName = fileName.Replace(':', '.');
            printscreen.Save(fileName, ImageFormat.Jpeg);

            Mailer.SendMail(mailAddress, "ScreenShot", fileName, null);

            return true;
        }

        #endregion
    }
}
